package com.wpen.unit.web.controller;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wpen.unit.service.AgentService;
import com.wpen.unit.web.dto.ContextRequest;
import com.wpen.unit.web.dto.ContextResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * agent操作接口
 * 
 * @author Wang Peng
 *
 */
@Tag(name = "agent操作接口")
@RestController
@RequestMapping("/api")
public class AgentController {
    @Autowired
    private AgentService agentService;

    @Operation(summary = "执行任务")
    @PostMapping(value = "/agent/start", produces = MediaType.APPLICATION_JSON_VALUE)
    public ContextResponse start(@RequestBody @Valid ContextRequest contextRequest) {
        return agentService.startTask(contextRequest);
    }
    
//    @Operation(summary = "停止任务")
//    @PostMapping(value = "/agent/stop", produces = MediaType.APPLICATION_JSON_VALUE)
//    public ContextResponse stop(@RequestBody @Valid ContextRequest contextRequest) {
//        return agentService.stopTask(contextRequest);
//    }

    @Operation(summary = "终止任务")
    @PostMapping(value = "/agent/kill", produces = MediaType.APPLICATION_JSON_VALUE)
    public ContextResponse kill(@RequestBody @Valid ContextRequest contextRequest) {
        return agentService.killProcess(contextRequest);
    }

    @Operation(summary = "检测任务")
    @PostMapping(value = "/agent/check", produces = MediaType.APPLICATION_JSON_VALUE)
    public ContextResponse check(@RequestBody ContextRequest contextRequest) throws Exception {
        return agentService.checkTask(contextRequest);
    }

    @Operation(summary = "删除任务")
    @PostMapping(value = "/agent/remove", produces = MediaType.APPLICATION_JSON_VALUE)
    public ContextResponse remove(@RequestBody ContextRequest contextRequest) throws Exception {
        return agentService.removeTask(contextRequest);
    }

}
